"use strict";

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

var _require = require('selenium-webdriver'),
    Builder = _require.Builder,
    By = _require.By,
    Key = _require.Key,
    until = _require.until; //引用浏览器
// const edge = require('selenium-webdriver/edge');
// const ie = require('selenium-webdriver/ie');
// const firefox = require('selenium-webdriver/firefox');


var chrome = require('selenium-webdriver/chrome'); // const opera = require('selenium-webdriver/opera');
//ie和edge
// let ie_service = new ie.ServiceBuilder("/path/to/IEDriverServer.exe");
// let edge_service = new edge.ServiceBuilder("/path/to/msedgedriver.exe");
//火狐
// const options = new firefox.Options();
// options.setBinary("/path/to/geckodriver");
//谷歌驱动


chrome.setDefaultService(new chrome.ServiceBuilder('C:/WebDriver/bin/chromedriver.exe').build());
(function () {
  var _example = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
    var Chrome, element;
    return regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _context.next = 2;
            return new Builder().forBrowser('chrome').build();

          case 2:
            Chrome = _context.sent;
            _context.prev = 3;
            _context.next = 6;
            return chrome.get('https://item.jd.com/54881560400.html');

          case 6:
            // let css = Chrome.findElement(By.css('#cheese '))
            // let cheddar = cheese.findElement(By.id('cheddar'));
            // Enter text "cheese" and perform keyboard action "Enter"
            // let elements = Chrome.findElement(By.class('price'));
            element = chrome.findElement({
              "class": 'price'
            }); // let firstResult = await Chrome.wait(until.elementLocated(By.class('price')), 10000);

            _context.t0 = console;
            _context.next = 10;
            return element.getAttribute('textContent');

          case 10:
            _context.t1 = _context.sent;

            _context.t0.log.call(_context.t0, _context.t1);

          case 12:
            _context.prev = 12;
            chrome.quit();
            return _context.finish(12);

          case 15:
          case "end":
            return _context.stop();
        }
      }
    }, _callee, null, [[3,, 12, 15]]);
  }));

  function example() {
    return _example.apply(this, arguments);
  }

  return example;
})()();
